home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / ExecutiveTest / ExecApp.m < prev    next >
Text File  |  1995-06-12  |  3KB  |  147 lines

  1. # import <appkit/Panel.h>
  2. # import <appkit/Button.h>
  3. # import <appkit/ScrollView.h>
  4. # import <appkit/ActionCell.h>
  5. # import <appkit/Cursor.h>
  6. # import "ExecApp.h"
  7.  
  8. @implementation ExecApp
  9.  
  10. + new
  11. {
  12.     self = [super new];
  13.     executive = [[[Executive new] setTarget:self]
  14.                         setAction:@selector(commandDone:result:)];
  15.     return(self);
  16. }
  17.  
  18. - free
  19. {
  20.     [queueMatrix free];
  21.     return([super free]);
  22. }
  23.  
  24. - setCommand:anObject
  25. {
  26.     command = anObject;
  27.     return(self);
  28. }
  29.  
  30. - setAsync:anObject
  31. {
  32.     async = anObject;
  33.     return(self);
  34. }
  35.  
  36. - setCommandType:anObject
  37. {
  38.     commandType = anObject;
  39.     return(self);
  40. }
  41.  
  42. - setPipeOutputWindow:anObject
  43. {
  44.     pipeOutputWindow = anObject;
  45.     return(self);
  46. }
  47.  
  48. - setPipeOutputSV:anObject
  49. {
  50.     pipeOutputSV = anObject;
  51.     pipeOutputText = [pipeOutputSV docView];
  52.     return(self);
  53. }
  54.  
  55. - setUpScrollView:sv
  56. {    NXRect            r;
  57.     Matrix            *mat;
  58.     static NXSize    inter = { 0.0, 0.0 };
  59.     NXSize            size;
  60.  
  61.     [sv setBackgroundGray:NX_LTGRAY];
  62.     [sv getDocVisibleRect:&r];
  63.     [[sv setDocView:(mat = [Matrix newFrame:&r mode:NX_LISTMODE
  64.                                                         cellClass:[ActionCell class]
  65.                                                         numRows:0
  66.                                                         numCols:1])] free];
  67.     [sv setDocCursor:NXArrow];
  68.     [mat setAutoscroll:YES];
  69.     [mat getCellSize:&size];
  70.     size.width = r.size.width;
  71.     size.height -= 2;
  72.     [[[mat setCellSize:&size] setIntercell:&inter] setBackgroundGray:NX_LTGRAY];
  73.     return(mat);
  74. }
  75.  
  76. - setQueueSV:anObject
  77. {
  78.     queueSV = anObject;
  79.     queueMatrix = [self setUpScrollView:queueSV];
  80.     return(self);
  81. }
  82.  
  83. - commandDone:(int)which result:(int)err
  84. {    int            row,col;
  85.  
  86.     NXRunAlertPanel("Async Command Done",
  87.                         (err == 0) ? "No errors" : "However, error %d occurred.",
  88.                         "Good",NULL,NULL,err);
  89.     [queueMatrix getRow:&row andCol:&col ofCell:[queueMatrix findCellWithTag:which]];
  90.     [queueMatrix removeRowAt:row andFree:YES];
  91.     [queueMatrix sizeToCells];
  92.     [queueSV display];
  93.     return(self);
  94. }
  95.  
  96. - pipeLine:(const char *)line
  97. {    int    len = [pipeOutputText textLength];
  98.  
  99.     [[pipeOutputText setSel:len :len] replaceSel:line];
  100.     return(self);
  101. }
  102.  
  103. - pipeLine:(int)result line:(const char *)line
  104. {
  105.     return([self pipeLine:line]);
  106. }
  107.  
  108. - takeUpdatePeriodFrom:sender
  109. {
  110.     [executive setPeriod:[sender doubleValue]];
  111.     return(self);
  112. }
  113.  
  114. - execute:sender
  115. {    int        result = 0;
  116.     BOOL        runAsync;
  117.     char        s[2048];
  118.  
  119.     runAsync = [async intValue];
  120.     if ([[commandType selectedCell] tag] == 0)
  121.         result = [executive execute:[command stringValue] async:runAsync];
  122.     else
  123.     {    [pipeOutputWindow makeKeyAndOrderFront:self];
  124.         result = [executive pipe:[command stringValue] to:self
  125.                     :((runAsync) ? @selector(pipeLine:line:) : @selector(pipeLine:))
  126.                     async:runAsync];
  127.     }
  128.     if (runAsync)
  129.     {    int            insLoc;
  130.     
  131.         sprintf(s,"[%d] %s",result,[command stringValue]);
  132.         [queueMatrix addRow];
  133.         insLoc = [queueMatrix cellCount]-1;
  134.         [[[queueMatrix cellAt:insLoc :0] setStringValue:s] setTag:result];
  135.         [queueMatrix sizeToCells];
  136.         [queueSV display];
  137.     }
  138.     else
  139.     {    NXRunAlertPanel("Sync Command Done",
  140.                                     (result == 0) ? "No errors" : "However, error %d occurred.",
  141.                                     "Good",NULL,NULL,result);
  142.     }
  143.     return(self);
  144. }
  145.  
  146. @end
  147.